import { Model , DataTypes } from "sequelize"
import { sequelize } from "../config/index.js"

// 定义一个 User 类 继承 Model
class User extends Model {}

// 通过 init 方法定义表的字段等信息
User.init(
  {
    username: {
      type: DataTypes.STRING, 
      allowNull: false,       
      unique: true,           
    },
    password: {
      type: DataTypes.STRING, 
      allowNull: false,       
    },
    email: {
      type: DataTypes.STRING, 
      allowNull: false,       
      unique: true,           
    },
    createdAt: {
      type: DataTypes.DATE,   
      allowNull: false,       
      defaultValue: DataTypes.NOW, 
    },
    lastLogin: {
      type: DataTypes.DATE,   
      allowNull: true,        
    },
  },
  { sequelize, modelName: 'User' } 
)

export default User